import { koa } from '@/service/config'

interface fileType {
  file: File
  filename?: string | number
}

export function getAvatarUpload(data: fileType):any {
  return koa.uploadFile({
    url: `/file/uploadAvatar`,
    data,
  })
}

export function getDownload(filename: string, callback) {
  return koa.get({
    url: `/file/download`,
    responseType: 'blob',
    timeout: 1000 * 60 * 60,
    params: {
      filename,
    },
    onDownloadProgress({ loaded, total }) {
      const progress = ((loaded / total) * 100).toFixed(2)
      callback(Number(progress))
    },
  })
}

export function getBigFileUploadApi(data: fileType) {
  return koa.uploadFile({
    url: `/file/bigFileUpload`,
    data,
    timeout: 1000 * 60 * 60,
    onUploadProgress({ progress }) {},
  })
}

export function getFinishChunkListApi() {
  return koa.get({
    url: `/file/finishChunk`,
  })
}

export function getFileDeleteApi(filename:string) {
  return koa.get({
    url: `/file/deleteFile`,
    params:{
      filename
    }
  })
}

export function getMergeFileApi() {
  return koa.get({
    url: `/file/mergeFile`,
  })
}

export function getFileListApi() {
  return koa.get({
    url: `/file/fileList`,
  })
}
